#!/usr/bin/env python
"""
# -*- coding: utf-8 -*-
# @Time    : 2020/9/30 13:16
# @Author  : AshJo
# @Desc    : 
# @Filename: server.py
# @Version : v1.0
"""

import socket

friend_lst = {'小强': '32', '小明': '33'}
sk = socket.socket(type=socket.SOCK_DGRAM)
sk.bind(('127.0.0.1', 9000))

while True:
    msg, addr = sk.recvfrom(1500)
    msg = msg.decode('utf-8')
    name, message = msg.split('|')
    print('\033[1;%sm %s : %s\033[0m' % (friend_lst.get(name, '30'), name, message))
    contect = input('>>>')
    sk.sendto(contect.encode('utf-8'), addr)
    if contect.upper() == 'Q':
        break
